<template>
	<view>
		<view class="notice-item" v-for="item in noticeList" :key="item.id">
			<text class="time">{{$u.timeFormat(item.created, 'yyyy年mm月dd日 hh时MM分')}}</text>
			
			<view class="content">
				<text class="title">{{item.title}}</text>
				<view class="img-wrapper" v-if="item.img">
					<image class="pic" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556465765776&di=57bb5ff70dc4f67dcdb856e5d123c9e7&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01fd015aa4d95fa801206d96069229.jpg%401280w_1l_2o_100sh.jpg"></image>
				</view>
				<text class="introduce">
				{{item.content}}
				</text>
				<view class="bot b-t">
					<text>查看详情</text>
					<text class="more-icon yticon icon-you"></text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { ListNotice } from "@/api/notice";
	export default {
		data() {
			return {
				noticeList:[]
			}
		},
		methods: {
			formatTimestamp(timestamp) {
				  const date = new Date(timestamp * 1000); // 将秒级时间戳转换为毫秒级
				  const year = date.getFullYear(); // 年份
				  const month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份（补0）
				  const day = ('0' + date.getDate()).slice(-2); // 日（补0）
				  const hours = ('0' + date.getHours()).slice(-2); // 小时（补0）
				  const minutes = ('0' + date.getMinutes()).slice(-2); // 分钟（补0）
				  const seconds = ('0' + date.getSeconds()).slice(-2); // 秒（补0）

				  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			}
		},
		async onLoad() {
			let res = await ListNotice({
				'page_num':1,
				'page_size':15
			})
			let list = res.data.item
			for (var i = 0; i < list.length; i++) {
				list[i].created = this.formatTimestamp(list[i].created)
			}
			this.noticeList = list
		}
	}
</script>

<style lang='scss'>
	page {
		background-color: #f7f7f7;
		padding-bottom: 30upx;
	}

	.notice-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.time {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80upx;
		padding-top: 10upx;
		font-size: 26upx;
		color: #7d7d7d;
	}

	.content {
		width: 710upx;
		padding: 0 24upx;
		background-color: #fff;
		border-radius: 4upx;
	}

	.title {
		display: flex;
		align-items: center;
		height: 90upx;
		font-size: 32upx;
		color: #303133;
	}

	.img-wrapper {
		width: 100%;
		height: 260upx;
		position: relative;
	}

	.pic {
		display: block;
		width: 100%;
		height: 100%;
		border-radius: 6upx;
	}

	.cover {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, .5);
		font-size: 36upx;
		color: #fff;
	}

	.introduce {
		display: inline-block;
		padding: 16upx 0;
		font-size: 28upx;
		color: #606266;
		line-height: 38upx;
	}

	.bot {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 80upx;
		font-size: 24upx;
		color: #707070;
		position: relative;
	}

	.more-icon {
		font-size: 32upx;
	}
</style>
